package com.xinruke.hostels.systemmanage.controller;

import com.xinruke.hostels.common.controller.BaseController;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.common.vo.query.RowsDataVO;
import com.xinruke.hostels.system.manage.interfaces.dto.*;
import com.xinruke.hostels.systemmanage.service.Impl.RoomTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author GuoZheng
 * @ClassName RoomTypeController
 * @date：2019/6/23
 * @version: 1.0
 * @description：房间类型管理
 */
@RestController
@RequestMapping("room-type/")
@Api(tags = "房间类型管理")
@Slf4j
public class RoomTypeController extends BaseController {

    @Resource
    private RoomTypeService roomTypeService;

    @PostMapping("/add")
    @ApiOperation("添加")
    public ResultVO add(@RequestBody @Valid RoomTypeAddDTO roomTypeAddQueryResultDTO) {
        return roomTypeService.add(roomTypeAddQueryResultDTO);
    }

    @PostMapping("/modify")
    @ApiOperation("修改")
    public ResultVO modify(@Valid @RequestBody RoomTypeModifyDTO roomModifyQueryDTO) {
        return roomTypeService.modify(roomModifyQueryDTO);
    }

    @PostMapping("/del")
    @ApiOperation("删除")
    public ResultVO del(@Valid @RequestBody RoomTypeDelResultDTO roomDelQueryResultDTO) {
        return roomTypeService.del(roomDelQueryResultDTO);
    }

    @PostMapping("/stop")
    @ApiOperation("禁用")
    public ResultVO stop(@Valid @RequestBody RoomTypeStopDTO params) {
        return roomTypeService.stop(params);
    }

    /**
     * pms通过酒店id查询旗下所有房间
     *
     * @return
     */
    @PostMapping("hotel")
    @ApiOperation(value = "PMS查询登录用户酒店下所有房间类别")
    public ResultVO<RowsDataVO<PMSRoomTypeQueryResultDTO>> getPMSRoomType(@Valid @RequestBody PMSRoomTypeQueryDTO underHotelQueryDTO) {

        return roomTypeService.getPMSRoomType(underHotelQueryDTO);
    }

    @PostMapping("booking/list")
    @ApiOperation(value = "查询预订房间类型集合")
    public ResultVO<RowsDataVO<BookingRoomTypeQueryResultDTO>> getBookingRoomTypeList(@Valid @RequestBody BookingRoomTypeQueryDTO bookingRoomTypeQueryDTO) {
        ResultVO resultVO = ResultVO.success();

        RowsDataVO rowsDataVO = roomTypeService.getBookingRoomTypeList(bookingRoomTypeQueryDTO);

        resultVO.setData(rowsDataVO);
        return resultVO;
    }

    /**
     * 预订通过酒店id查询旗下所有房间
     *
     * @return
     */
    @PostMapping("reservation/hotel")
    @ApiOperation(value = "预订系统查询指定酒店下所有房间类别")
    public ResultVO<RowsDataVO<ReservationRoomTypeQueryResultDTO>> getReservationRoomType(@Valid @RequestBody ReservationRoomTypeQueryDTO underHotelQueryDTO) {

        return roomTypeService.getReservationRoomType(underHotelQueryDTO);
    }

    /**
     * @return
     */
    @PostMapping("detail")
    @ApiOperation(value = "房间类别详情")
    public ResultVO<RoomTypeDetailQueryResultDTO> getDetail(@Valid @RequestBody RoomTypeDetailQueryDTO underHotelQueryDTO) {
        ResultVO<RoomTypeDetailQueryResultDTO> resultVO = ResultVO.fail();

        RoomTypeDetailQueryResultDTO dataVO = roomTypeService.getDetail(underHotelQueryDTO);
        if (null == dataVO) {
            return ResultVO.fail("没有获取到此类别");
        }
        resultVO.setCode(ResultVO.SUCCESS);
        resultVO.setMessage("操作成功");
        resultVO.setData(dataVO);

        return resultVO;
    }

}
